<?php

/**
 * Post
 * 
 * @package    iceblog
 * @subpackage model
 * @author     Jonathan Nieto
 */
class Post extends BasePost
{
  public function getUserRealname()
  {
    return $this->getUser()->getRealname();
  }
  
  public function save(Doctrine_Connection $conn = null)
  {
    if ($this->isNew() && sfContext::hasInstance())
    {
      $this->setUserId(sfContext::getInstance()->getUser()->getUserId());
      $this->setDatetime(date('Y-m-d H:i:s'));
    }
    
    if ($this->isColumnModified('content'))
    {
      $this->setExcerpt(substr($this->getContent(), 0, 255));
    }
    
    parent::save($conn);
  }
  
  public function getFormattedDatetime($format = 'D')
  {
    return $this->getTable()->getDateTimeFormatter()->format($this->getDatetime(), $format);
  }
  
  public function getLink()
  {
    return link_to($this->getTitle(), '@post_show?slug='.$this->getSlug());
  }
}
